import {BaseGCG} from "../BaseGCG.js";
import {Log} from "../log/Log.js";
import {DirectionConstant} from "../constants/DirectionConstant.js";

/**
 * 子弹控制
 * [一般来说子弹都是跟随本体正前方]
 */
export class Fire extends BaseGCG{
    //fire跟随本体元素
    _noumenon = null;
    //fire元素
    _fire = null;
    //默认射击方向
    derection = 'up';
    constructor(noumenon, fire) {
        super();

        this._noumenon = noumenon;
        this._fire = fire;
    }

    /**
     * 本体属性检查
     */
    noumenonCheck(){
        Log.log('本体属性检查');
        if(!this._noumenon) throw new Error('本体不存在');

    }



    // /**
    //  * 设置默认坐标
    //  */
    // setDefaultPosition(){
    //     if(this.derection === DirectionConstant.UP){
    //         this.setTop(this._fire, this.getTop(this._noumenon));
    //         this.setLeft(this._fire, this.getLeft(this._noumenon));
    //     }
    //
    // }

    /**
     * 设置子弹跟随本体
     */
    follow(){

        if(this.derection === DirectionConstant.UP){
            this.setTop(this._fire, this.getTop(this._noumenon));
            this.setLeft(this._fire, this.getLeft(this._noumenon) + this.getAllWidth(this._noumenon)/2 - this.getAllWidth(this._fire)/2);
        }
        if(this.derection === DirectionConstant.DOWN){
            this.setTop(this._fire, this.getTop(this._noumenon));
            this.setLeft(this._fire, this.getLeft(this._noumenon) + this.getAllWidth(this._noumenon)/2 - this.getAllWidth(this._fire)/2);
        }
        if(this.derection === DirectionConstant.LEFT){
            this.setTop(this._fire, this.getTop(this._noumenon) + this.getAllWidth(this._noumenon)/2 - this.getAllWidth(this._fire)/2);
            this.setLeft(this._fire, this.getLeft(this._noumenon));
        }
        if(this.derection === DirectionConstant.RIGHT){
            this.setTop(this._fire, this.getTop(this._noumenon) + this.getAllWidth(this._noumenon)/2 - this.getAllWidth(this._fire)/2);
            this.setLeft(this._fire, this.getLeft(this._noumenon));
        }

        // this.setTop(this._fire, this.getTop(this._noumenon));
        // this.setLeft(this._fire, this.getLeft(this._noumenon));

    }
}